package com.neusoft.bigdata.hbase;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.HTable;

import com.neusoft.bigdata.hbase.util.DataCalculUtil;
import com.neusoft.bigdata.hbase.util.HBaseDataUtil;

/**
 * 用于数据计算处理的工具类
 * 
 * @author lihzh
 * @date 2013-4-1 下午5:25:07
 */
public class ForDataCalculate {

	private static final long HOUR_MILLION_SECONDS = 3600 * 1000L;
	private static Configuration conf = null;
	private static HTable METRIC_HTABLE;

	static {
		Configuration HBASE_CONFIG = new Configuration();
		conf = HBaseConfiguration.create(HBASE_CONFIG);
		try {
			METRIC_HTABLE = new HTable(conf, ForPrepareData.TABLE_NAME_METRIC);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 根据资源fqn，计算该资源每小时的所有指标的平均值
	 * 1320112740000L
	 * 
	 * @param fqn
	 * @author lihzh
	 * @throws IOException
	 * @date 2013-4-1 下午5:26:22
	 */
	public void calHourAvgByFQN(String fqn, long startPoint) throws IOException {
		DataCalculUtil.calAvg(HBaseDataUtil.getByFQN(METRIC_HTABLE, fqn, startPoint, HOUR_MILLION_SECONDS));
	}

}
